<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" type="text/css" href="__TMPL__/public/order/css/newaddress.css"/>
    <script type="text/javascript" src="__TMPL__/public/assets/js/jquery.min.js"></script>
    <link rel="stylesheet" type="text/css" href="__TMPL__/public/assets/css/mobileSelect.css"/>
    <script src="__TMPL__/public/assets/js/mobileSelect.min.js"></script>
    <script type="text/javascript" src="__TMPL__/public/assets/js/layer/layer.js"></script>
    <script type="text/javascript" src="__TMPL__/public/assets/js/selectDate.js"></script>
    <script type="text/javascript" src="__TMPL__/public/assets/js/lrz.all.bundle.js"></script>
    <style>
        #trigger2{display: block;width: 74%;float: right;height: 45px;text-align: left;font-size: 13px;color: #222222;}
    </style>
    <title>收货地址</title>
</head>
<body>
<header>
    <div class="content" style="border-bottom: 1px solid rgba(215, 215, 215, 0.29);">
        <a href="javascript:history.back(-1);"></a>
        <a>新建收货地址</a>
        <a href="javascript:;"></a>
    </div>
</header>
<div class="information">
    <div>联系人<input type="text" placeholder="收货人姓名" id="consigner"/></div>
    <div>手机号<input type="number" placeholder="收货手机号" id="mobile"/></div>
    <div>收货地址 <span  id="trigger2">请选择</span></div>
    <div>门牌号<input type="text" placeholder="详细地址，例：4号楼2单元605室" id="address"/></div>
</div>
<input type="hidden" id="province">
<input type="hidden" id="city">
<input type="hidden" id="district">
<div class="save">保存</div>
<script>
    <php>
    if(input('type')){
    </php>
        var href="/user/profile/address/type/1.html";
    <php>
    }else{
    </php>
        var href="/user/profile/address.html";
    <php>
    }
    </php>
    $(function () {
        var mobileSelect2 = new MobileSelect({
            trigger: '#trigger2',
            title: '地区选择',
            wheels: [
                {data:{$province}}
            ],
            callback:function(indexArr, data){
                $('#province').val(data[0]['id'])
                $('#city').val(data[1]['id'])
                $('#district').val(data[2]['id'])
            }
        });

        $('.save').click(function () {
            var province=$('#province').val();
            var city=$('#city').val();
            var district=$('#district').val();
            var consigner=$('#consigner').val();
            var mobile=$('#mobile').val();
            var address=$('#address').val();
            if(consigner==''){
                layer.msg('请填写收件人名字');
                return;
            }
            if(mobile==''){
                layer.msg('请填写收件人手机号');
                return;
            }
            if(province==''||city==''||district==''){
                layer.msg('请选择地区');
                return;
            }

            if(address==''){
                layer.msg('请填写收件人详细地址');
                return;
            }
            var reg = /^1[34578]\d{9}$/;

            if (!reg.test(mobile)) {
                layer.msg('请输入正确的手机号码');
                return;
            }
            $.ajax({
                url : '/user/profile/add_address.html',
                type : "post",
                data : {
                    "province" : province,
                    "city" : city,
                    "district" : district,
                    "consigner" : consigner,
                    "mobile" : mobile,
                    "address" : address
                    },
                success : function(res){
                    layer.msg(res.msg);
                    location.href=href;
                }
            });

        })
    })
</script>
</body>
</html>
